home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / examples / chap03 / ChangeColor.java < prev    next >
Text File  |  1996-09-05  |  773b  |  31 lines

  1. import vrml.*;
  2. import vrml.field.*;
  3. import vrml.node.*;
  4.  
  5. public class ChangeColor extends Script {
  6.  
  7.   private SFBool on;      // status of on-off
  8.   float red[] =  { 1, 0, 0 };      // RGB(Red)
  9.   float blue[] = { 0, 0, 1 };      // RGB(Blue)
  10.   private SFColor newColor ;
  11.  
  12.   public void initialize() {   
  13.  
  14.     newColor = (SFColor) getEventOut("newColor");
  15.     on = (SFBool) getField("on");
  16.   }
  17.  
  18.   public void processEvent(Event e) {
  19.     ConstSFBool v = (ConstSFBool)e.getValue();
  20.  
  21.     if(v.getValue()){
  22.       if (on.getValue()) {
  23.         newColor.setValue(red);     // set red to 'newColor'
  24.       } else {
  25.         newColor.setValue(blue);    // set blue to 'newColor'
  26.       }
  27.       on.setValue(!on.getValue());  // = !on.getValue();
  28.     }
  29.   }
  30. }
  31.